package com.boruishangge.home.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import androidx.annotation.NonNull;
import androidx.databinding.DataBindingUtil;
import androidx.recyclerview.widget.RecyclerView;

import com.boruishangge.home.R;
import com.boruishangge.home.databinding.ItemHomeListViewBindingImpl;

import java.util.List;

public class ListAdapter extends RecyclerView.Adapter<ListAdapter.ListViewHolder> {



    private List<String> list;
    private LayoutInflater inflater;
    Context mContext;

    public ListAdapter(List<String> list, Context mcontex) {
        this.list = list;
        this.mContext = mcontex;
        this.inflater = LayoutInflater.from(mContext);
    }

    @NonNull
    @Override
    public ListViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        return new ListViewHolder(inflater.inflate( R.layout.item_home_list_view, parent, false));

    }

    @Override
    public void onBindViewHolder(@NonNull ListViewHolder holder, int position) {
        holder.bind(list.get(position));
    }


    @Override
    public int getItemCount() {
        return null == list ? 0 : list.size();
    }


    class  ListViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener {

        ItemHomeListViewBindingImpl binding;
        String name;

        public ListViewHolder(@NonNull View itemView) {
            super(itemView);
            binding= DataBindingUtil.bind(itemView);

            binding.rvItem.setOnClickListener(this);
        }



        public  void bind(String bean){
            name=bean;
            binding.tvTitle.setText(bean);

        }

        @Override
        public void onClick(View v) {
            // "isProcess":"0",//0未处理,1已处理

            if (v==binding.rvItem){
                if (onChoseNineClick!=null){
                    onChoseNineClick.onChoseNineClick(name);
                }

            }

        }


    }



    private onChoseNineClick onChoseNineClick;

    public void setOnChoseNineClick(ListAdapter.onChoseNineClick onChoseNineClick) {
        this.onChoseNineClick = onChoseNineClick;
    }

    public interface onChoseNineClick {
        void onChoseNineClick(String value);

    }
}
